go to previous page   go to home page   go to next page

Answer:

Good Dog


Integer

Examine the following declarations. They use the wrapper class Integer discussed at the end of chapter 9C. An Integer object holds an integer as its data and provides several useful methods for working with integers. Class Integer implements the Comparable<Integer> interface and so has the compareTo method.

Integer minusTen = new Integer( -10 );
Integer minusFive = new Integer( -5 );
Integer five = new Integer( 5 );
Integer ten = new Integer( 10 );
Integer fifteen = new Integer( 15 );

For numbers, mentally replace "compareTo" with subtraction and do the arithmetic. For example, five.compareTo( ten ) works like five-ten.

What is the result of each of the following?

five.compareTo( ten )
ten.compareTo( five )
five.compareTo( five )
ten.compareTo( fifteen )
minusFive.compareTo( ten )
minusFive.compareTo( minusTen )

QUESTION 3:

Examine the following:

Integer five = 5 ;
Integer ten = 10 ;

What is the value of:

five.compareTo( ten )